package com.xauto.pioneer.appuser.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**订单详情
 * Created by Ellis.Li on 2017/5/12.
 */
public class OrderDetailInfo extends BaseModel<OrderDetailInfo> {

    /** 车辆订单ID*/
    public String car_order_id;
    /** 车辆订单编号*/
    public String car_order_no;
    /** 车辆订单状态ID*/
    public String car_order_status_id;
    /** 车辆订单状态名称*/
    public String car_order_status_name;
    /** 车辆订单备注*/
    public String car_order_remark;
    /** 车辆订单备注颜色(0-黑色/1-红色)*/
    public String car_order_remark_style_color;
    /** 订单开始时间(unix_time)*/
    public String order_start_time;
    /**订单结束时间(unix_time)*/
    public String order_end_time;
    /** 计费开始时间(unix_time)*/
    public String order_charge_start_time;
    /** 计费结束时间(unix_time)*/
    public String order_charge_end_time;
    /** 总计*/
    public String total_amount;
    /** 格式化(10.00元)*/
    public String total_amount_format;
    /** */
    public BillChargeInfo billing_charge_info;
    /** */
    public List<OrderTotalInfo> order_total_list;
    /** */
    public Payment payment_info;
    /** */
    public VoucherInfo voucher_info;
    /** */
    public CarInfo car_info;
    /** */
    public RefuelInfo  refuel_info;
    /**车辆附加费用*/
    public AdditionalInfo  additional_info;
    /**测试总公里数*/
    public  String test_total_kilometer;
    @Override
    public OrderDetailInfo parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            car_order_id = jsonObject.optString("car_order_id");
            car_order_no = jsonObject.optString("car_order_no");
            car_order_status_id = jsonObject.optString("car_order_status_id");
            car_order_status_name = jsonObject.optString("car_order_status_name");
            car_order_remark = jsonObject.optString("car_order_remark");
            car_order_remark_style_color = jsonObject.optString("car_order_remark_style_color");
            order_start_time = jsonObject.optString("order_start_time");
            order_end_time = jsonObject.optString("order_end_time");
            order_charge_start_time = jsonObject.optString("order_charge_start_time");
            order_charge_end_time = jsonObject.optString("order_charge_end_time");
            total_amount = jsonObject.optString("total_amount");
            total_amount_format = jsonObject.optString("total_amount_format");
            billing_charge_info = new BillChargeInfo().parse(jsonObject.optJSONObject("billing_charge_info"));
            JSONArray totalList = jsonObject.optJSONArray("order_total_list");
            if (totalList != null){
                order_total_list = new ArrayList<>();
                for (int i=0,length = totalList.length();i<length;i++){
                    OrderTotalInfo totalInfo = new OrderTotalInfo().parse(totalList.optJSONObject(i));
                    order_total_list.add(totalInfo);
                }
            }
            payment_info = new Payment().parse(jsonObject.optJSONObject("payment_info"));
            voucher_info = new VoucherInfo().parse(jsonObject.optJSONObject("voucher_info"));
            car_info = new CarInfo().parse(jsonObject.optJSONObject("car_info"));
            refuel_info = new RefuelInfo().parse(jsonObject.optJSONObject("refuel_info"));
            additional_info= new AdditionalInfo().parse(jsonObject.optJSONObject("additional_info"));
            test_total_kilometer= jsonObject.optString("test_total_kilometer");
            return this;
        }
        return null;
    }
}
